<template>
  <rx-dialog @handOk="onOk" @cancel="cancel">
    <comment ref="current" :is="currentView" :layerid="layerid" :destroy="destroy"></comment>
  </rx-dialog>
</template>

<script>
    import {RxDialog, Util} from "@lowcode/jpaas-common-lib";
    import rowControls from '../../../../api/form/core/rowcontrols';
    export default {
      name: "RowControls",
      components: {RxDialog},
      props:["row","curFields","layerid","destroy"],
      data(){
        return {
          currentView:''
        }
      },
      computed:{
        current(){
          return this.$refs.current;
        },
      },
      created() {
        this.currentView=rowControls['rowControl_'+this.row.control];
      },
      mounted(){
        this.setData();
      },
      methods:{
        onOk(e){
          var self=this;
          if(this.current.validate(function(){
            Util.closeWindow(self, "ok");
          }));
          e.loading =false;
        },
        cancel(){
          Util.closeWindow(this,"cancel");
        },
        setData() {
          var controlConf=this.row.controlConf;
          if(!controlConf) controlConf="{}";
          controlConf=JSON.parse(controlConf);
          controlConf.field=this.row.field;
          if(!controlConf.maxLength){
            controlConf.maxLength=this.row.width;
          }
          if(this.current){
            this.current.setData(controlConf, this.curFields);
          }

        },
        getData(){
          return this.current.getData();
        }
      }
    }
</script>

<style scoped>

</style>